package com.distributor;

import android.app.AlertDialog;
import android.app.TabActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TextView;

public class Tab_Reseller extends TabActivity implements OnTabChangeListener
{
	TabHost tabHost;
	TabHost.TabSpec spec;
 	Intent intent; 
    Resources res;
    Button btnback,btnlogout;
    TextView txtheader;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		
		Integer fvalue=(Integer) getIntent().getExtras().get("calleractivity");
		
		
		setContentView(R.layout.tab_layout_reseller);
		
		btnback=(Button)findViewById(R.id.btnPrevious);
		btnlogout=(Button)findViewById(R.id.btnLogout);
		txtheader=(TextView)findViewById(R.id.tv_headerText);
		
		if(fvalue==10)
		{
			txtheader.setText("Favourite");
		}
		
		
		
		  res = getResources(); 
	        tabHost = getTabHost();
	       
	        intent=new Intent().setClass(this, ResellerResult.class);
	        spec = tabHost.newTabSpec("Info").setIndicator("")
	                .setContent(intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
	        tabHost.addTab(spec);
	        
	        intent=new Intent().setClass(this, AddBalance.class);
	        spec = tabHost.newTabSpec("Add Balance").setIndicator("")
	                .setContent(intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
	        tabHost.addTab(spec);
	        
	        

	        intent=new Intent().setClass(this, WeeklyStatementActivity.class);
	        spec = tabHost.newTabSpec("Weekly Statement").setIndicator("")
	                .setContent(intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
	        tabHost.addTab(spec);
	        
	        tabHost.setCurrentTab(0);
	        
	        for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
	            tabHost.getTabWidget().getChildAt(i).getLayoutParams().height /=1.2;

	        }
	        tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.information_hover);
	        tabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.weekly_statement);
	        tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.add_balanace);
	        
	        
	        tabHost.setOnTabChangedListener(this);
	        
	        btnlogout.setOnClickListener(new OnClickListener() {
				
				public void onClick(View v) {
					// TODO Auto-generated method stub
					new AlertDialog.Builder(Tab_Reseller.this)
					  .setTitle( "Exit Application" )
				      .setMessage( "Are you sure you want to Logout?" )
				      .setPositiveButton("YES", new android.content.DialogInterface.OnClickListener() 
				       {
				           public void onClick(DialogInterface arg0, int arg1) 
				           {
				        	   setResult(1);
				               finish();
				           }
	
						   public void onClick(View v) 
						   {
							 // TODO Auto-generated method stub
						   }
						   
				        })
				        .setNegativeButton("NO",  new android.content.DialogInterface.OnClickListener() 
				        {
				            public void onClick(DialogInterface arg0, int arg1)
				            {
				                //do stuff onclick of CANCEL
				            	arg0.dismiss();
				            }
	
							public void onClick(View v) 
							{
								// TODO Auto-generated method stub
							}
				        }).show();
			  	}
				
			});
	        
	        btnback.setOnClickListener(new OnClickListener() {
				
				public void onClick(View v) {
					// TODO Auto-generated method stub
					finish();
				}
			});
	}

	
	


	public void onTabChanged(String tabName)
	{
		 for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
	            tabHost.getTabWidget().getChildAt(i).getLayoutParams().height /=1.2;

	        }
		if(tabName.equalsIgnoreCase("Info"))
		{
			tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundResource(R.drawable.information_hover);
			tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.add_balanace);
		    tabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.weekly_statement);
		}
		else if(tabName.equalsIgnoreCase("Add Balance"))
		{
			tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundResource(R.drawable.add_balance_hover);
			tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.information);
		    tabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.weekly_statement);
		}
		else if(tabName.equalsIgnoreCase("Weekly Statement"))
		{
			tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundResource(R.drawable.weekly_statement_hover);
			tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.information);
		    tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.add_balanace);
		}
		
	}
	
}
